package ThreadPool.lagou.concurrent.interrupt.demo01;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

/**
 * @param
 * @author oyz
 * @version 1.0.4
 * @description: 线程打断的demo实现
 * @date 2022/10/9 20:24
 */
public class InterruptDemo {


    // 不需要加volite来保证可见性
    static AtomicBoolean atomicBoolean = new AtomicBoolean(false);

    public static void main(String[] args) throws InterruptedException {


    }

    public void test1()  throws InterruptedException {
        new Thread(()->{
            while (true){
                if(atomicBoolean.get()) {
                    System.out.println(Thread.currentThread().getName()+"修改为true");
                    break;
                }
                System.out.println("hello would");
            }
        },"a").start();

        TimeUnit.MILLISECONDS.sleep(20);

        new Thread(()->{
            atomicBoolean.set(true);
        },"b").start();
    }
}
